package com.itheima.demothreadsafe;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Account {
    private String cardId;
    private double money;
//小明和小红都到这里来取钱
    public void draw(double money) {
//        拿到当前谁来取钱
//        判断余额是否足够
        if (this.money >= money) {
            System.out.println(Thread.currentThread().getName() +"开始取钱");
//            余额足够，取钱
            this.money -= money;
            System.out.println(Thread.currentThread().getName() + "取钱成功，余额为：" + this.money);
        } else {
//            余额不足，取钱失败
            System.out.println(Thread.currentThread().getName() + "取钱失败，余额不足");
        }
    }
}
